package com.demo.association.manytomany;

import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Table(name = "USER_DETAILS")
public class UserDetailsDTO {

	private int userId;       //--- int.. 
	private String userName;   //sTRINGtYPE(---- varchar(255)
	private double salary;    //----- double 
	private String address;  //boolean --- 
	                         //custome type  -- type registry 
	                        //configuration .. 
	//1 TABLE PER CLASS HIERARCHY .. 
	//2:- tABLE PER CONCRETE CLASS
	 //3:-TABLE FOR SUBCLASS.
	 
    private Collection<RoleDetailsDTO> roleList=new ArrayList<RoleDetailsDTO>();
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "USER_ID")
	public int getUserId() {
		return userId;
	}

	@Column(name = "USER_NAME" ,columnDefinition="VARCHAR(50) default 'abc'")
	public String getUserName() {
		return userName;
	}

	@Column(name = "SALARY")
	public double getSalary() {
		return salary;
	}

	@Column(name = "ADDRESS")
	public String getAddress() {
		return address;
	}

	@ManyToMany(fetch=FetchType.EAGER)
	@JoinTable(name="USER_ROLE_MAPPING",joinColumns=@JoinColumn(name="USER_ID"),inverseJoinColumns=@JoinColumn(name="ROLE_ID"))
	public Collection<RoleDetailsDTO> getRoleList() {
		return roleList;
	}
	
	public void setRoleList(Collection<RoleDetailsDTO> roleList) {
		this.roleList = roleList;
	}
	
	
	
	
	public void setUserId(int userId) {
		this.userId = userId;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public void setSalary(double salary) {
		this.salary = salary;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@Override
	public String toString() {
		return "UserDetailsDTO [userId=" + userId + ", userName=" + userName
				+ ", salary=" + salary + ", address=" + address + "]";
	}

}
